﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head th:include="_meta :: header">
    <meta charset="utf-8">
    <title>角色管理</title>
</head>
<body>

<div class="x-nav">
<span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">系统管理</a>
            <a>
              <cite>分组管理</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="float: right;height: 30px;line-height: 30px;margin-top: 5px;"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<style>
    .layui-badge {
        cursor: pointer
    }
</style>


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form action="#" class="layui-form layui-col-space5" th:action="@{/role}" method="post">
                        <div class="cl pd-5 bg-1 bk-gray " >
						  <span class="l">
						     <a sec:authorize="hasAuthority('/role/delete')"
                                href="javascript:;"
                                th:onclick="'javascript:deleteAll(\''+@{/role/delete}+'\')'"
                                class="layui-btn  layui-btn-normal radius">
							     <i class="layui-icon">&#xe64d;</i> 批量删除
						      </a>
							  <a sec:authorize="hasAuthority('/role/add-role')"
                                 class="layui-btn  layui-btn-danger radius"
                                 href="javascript:;"
                                 onclick="admin_role_add('添加角色','/role/add-role', '', '500')">
								  <i class="layui-icon">&#xe600;</i> 添加角色
							  </a>
	                      </span><span class="r wei-height" style="float: right;margin-right: 20px">共有数据：<strong
                                th:text="${pageInfo.total}"></strong> 条</span>
                        </div>



                        <table class="layui-table layui-form ">
                            <thead>
                            <tr>
                                <th scope="col" colspan="6">角色管理</th>
                            </tr>

                            <tr class="text-c" >
                                <th width="30">
                                    <input type="checkbox" name="" value="" lay-filter="checkall" lay-skin="primary"/>
                                </th>
                                <th width="40">ID</th>
                                <th width="200">角色名</th>
                                <th>资源列表</th>
                                <th width="300">描述</th>
                                <th width="70">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <tr class="text-c" th:each="role,count:${pageInfo.list}">

                                <td>
                                    <input type="checkbox" value="1" th:value="${role.id}" name="id" lay-skin="primary"/>
                                </td>

                                <td th:text="${count.count}"></td>

                                <td th:text="${role.name}"></td>

                                <td>
                                    <span th:each="resource:${role.resources}"><span th:text="${resource.name}"></span>&nbsp;&nbsp;</span>
                                </td>

                                <td th:text="${role.description}"></td>
                                <td>

                                    <a title="编辑" sec:authorize="hasAuthority('/role/editor-role')" href="javascript:;"
                                       th:onclick="'javascript:admin_role_edit(\'角色编辑\',\''+@{/role/editor-role/}+${role.id}+'\',\'1\',\'\',\'510\')'"
                                       class="ml-5" style="text-decoration:none"><i
                                            class="layui-icon">&#xe642;</i></a>

                                    <a title="删除" sec:authorize="hasAuthority('/role/delete')" href="javascript:;"
                                       th:onclick="'javascript:admin_role_del(\''+${role.id}+'\',\''+@{/role/delete}+'\')'"
                                       class="ml-5" style="text-decoration:none"><i
                                            class="layui-icon">&#xe640;</i></a></td>
                            </tr>
                            </tbody>
                        </table>
                        <!--                        <div th:include="_pagination :: page"></div>-->

                        <div id="demo7"></div>














                    </form>
                </div>
                <!--_footer 作为公共模版分离出去-->
                <div th:replace="_footer :: footerjs">
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    layui.use(['form','layer','laypage','layer'], function(){
        var form = layui.form
            ,layer = layui.layer;
        form.on('checkbox(checkall)', function (data) {
            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });
        form.on('select(selectchange)', function(data){
            console.log(data.value); //得到被选中的值
            var pageNo = $('#pageNo');
            var Form = $('form')
            pageNo.val(1);
            Form.submit();
            form.render('select');
        });
    });

    function admin_role_add(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    /*管理员-角色-编辑*/
    function admin_role_edit(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }

    /*管理员-权限-删除*/
    function admin_role_del(id, url) {
        layer.confirm('确认要删除吗？', function (index) {
            var _list = new Array();
            _list[0] = id;
            $.ajax({
                type: 'POST',
                url: url,
                data: JSON.stringify(_list),
                type: 'post',
                cache: false,
                dataType: 'json',
                contentType: "application/json",  //发送信息至服务器时内容编码类型。
                success: function (data) {
                    //$(obj).parents("tr").remove();
                    if (data) {
                        window.location.reload();
                    } else {
                        layer.msg('删除失败!', {icon: 1, time: 1000});
                        window.location.reload();
                    }

                },
                error: function (data) {
                    console.log("资源访问失败");
                },
            });
        });
    }

    /*<![CDATA[*/
    /*批量删除*/
    function deleteAll(url) {
        var _list = new Array();
        $('input[name="id"]:checked').each(
            function (i) {
                _list[i] = $(this).val();
            });

        if (_list.length <= 0) {
            layer.msg("请选择删除的角色");
            return false;
        }
        layer.confirm('确定要删除选中的全部数据吗？', {
            btn: ['确定', '取消']
            // 按钮
        }, function () {
            $.ajax({
                url: url,// 跳转到 action
                data: JSON.stringify(_list),
                type: 'post',
                cache: false,
                dataType: 'json',
                contentType: "application/json",  //发送信息至服务器时内容编码类型。
                success: function (data) {
                    if (data == 1) {
                        window.location.reload();
                    } else {
                        layer.msg("删除失败");
                    }
                },
                error: function () {
                    layer.msg("异常！");
                }
            });
        }, function () {

        });
    }






    /*管理员-角色-添加*/


    /*]]>*/





</script>
</body>
</html>